package demo4;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class Main {
    public static void main(String[] args) {
        //建立选项
        String[] selects = {"A","B","C","D"};
        //建立StringBuilder用于存储投票
        StringBuilder stringBuilder = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < 80; i++) {
            stringBuilder.append(selects[random.nextInt(selects.length)]);
        }
        //创建Map集合
        Map<Character,Integer> maps = new HashMap<>();
        //遍历投票
        char ch;
        for (int i = 0; i < stringBuilder.length(); i++) {
            ch = stringBuilder.charAt(i);
            //检查是否已经包含此键
            if (maps.containsKey(ch)){
                //若有包含，先获取原来值，加一，再put
                maps.put(ch,maps.get(ch)+1);
                continue;
            }
            //若没有原来的值，则直接上传数值为1
            maps.put(ch,1);
        }
        System.out.println(maps);
    }
}
